<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
        因为输出结果是无重复的，所以可以用set先对num1,nums2进行一个去重
        */
      var intersection = function (nums1, nums2) {
        let res = [];
        let set1 = new Set(nums1);
        let set2 = new Set(nums2);
        for (let i of set1) {
          if (set2.has(i)) {
            res.push(i);
          }
        }
        return res;
      };
      console.log(intersection([4, 9, 5], [9, 4, 9, 8, 4]));
    </script>
  </body>
</html>
